<?php
/**
 * 用户管理模型
 * @author e5
 *
 */
class UserModel extends Model{
	public $table = "user";
	//自动验证
	public $validate = array(
			array('username','nonull','用户名不能为空',2,1),
			array('username','maxlen:20','用户名长度最大为20个字符',2,1),
			array('username','isExt','用户已存在',2,1),
			array('password','nonull','密码不能为空',2,3),
			array('password','minlen:6','密码最小长度不能小于6个字符',2,3),
			array('password','confirm:password1','2次密码输入不一致',2,3)
	);
	//自动完成
	public $auto = array(
			array("password","md5","function",2,3)
	);
	//自动映射
	public $map = array(
			"username"=>"uname",
			"password"=>"upwd"
	);
	/**
	 * 验证用户是否存在
	 * @param string $name
	 * @param string $value
	 * @param string $msg
	 * @param string $arg
	 */
	public function isExt($name,$value,$msg,$arg){
		if ($this->where("uname='{$value}'")->count() > 0){
			return $msg;
		}
		return true;
	}
	/**
	 * 用户注册
	 */
	public function register() {
		if (!$this->create()) return false;
		return $this->add();
	}
}